﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InterfaceFiles
{
  public class TextInterfaceFile : IInterfaceFile
  {
    IInterfaceReader reader;
    IInterfaceWriter writer;

    TextInterfaceHeader header;
    TextInterfaceRecord currentRecord;

    public TextInterfaceFile(string fileName)
    {
      reader = null;
      writer = new TextInterfaceWriter(fileName);
      header = new TextInterfaceHeader(reader, writer);
    }

    public TextInterfaceFile(IInterfaceReader reader, IInterfaceWriter writer)
    {
      this.reader = reader;
      this.writer = writer;
      header = new TextInterfaceHeader(reader, writer);
    }

    public void WriteRecord(IInterfaceRecord record)
    {
      throw new NotImplementedException();
    }

    public void WriteHeader(IInterfaceHeader header)
    {
      throw new NotImplementedException();
    }

    public IInterfaceRecord ReadRecord()
    {
      throw new NotImplementedException();
    }

    public IInterfaceHeader ReadHeader()
    {
      throw new NotImplementedException();
    }

    public void WriteInterface(IInterfaceFile interfaceFile)
    {
      IInterfaceHeader readHeader = interfaceFile.ReadHeader();
      header.Write(readHeader);
      List<string> nodes = readHeader.Nodes;

      while (!(interfaceFile.IsEndOfFile))
      {
        IInterfaceRecord record = interfaceFile.ReadRecord();
        currentRecord = new TextInterfaceRecord(null, writer, nodes);
        currentRecord.Write(record);
      }
    }

    public bool IsEndOfFile
    {
      get { return reader.IsEndOfFile; }
    }
  }
}
